<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>JTable 为单元格添加按钮效果和事件效果 - 銠槍--突廆孒 - 博客频道 - CSDN.NET</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="一、添加按钮显示效果在JTable中，单元格的数据默认是Label的效果，也没有事件。如果要为单元格添加一个按钮显示效果的话，那么就需要使用到一个swing的接口：javax.swing.table.TableCellRenderer，来改变单元桥格的默认默认渲染方法（DefaultTableCellRenderer），实现的自定义的渲染器如下：&nbsp;package org.sky">
<script src="7798046_files/log.js" async="" charset="utf-8"></script><script src="7798046_files/ga.js" async="" type="text/javascript"></script><script src="7798046_files/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="7798046_files/ad.js"></script>
<link rel="Stylesheet" type="text/css" href="7798046_files/style_002.css">
<link id="RSSLink" title="RSS" type="application/rss+xml" rel="alternate" href="http://blog.csdn.net/sbfivwsll/rss/list">
<link rel="shortcut icon" href="http://blog.csdn.net/favicon.ico">
<link type="text/css" rel="stylesheet" href="7798046_files/default.css">
<link href="7798046_files/style.css" rel="stylesheet" type="text/css"></head>
<body>
<script src="7798046_files/pub_topnav_2011.js" type="text/javascript"></script><link rel="stylesheet" type="text/css" href="7798046_files/navtop_2012.css">
<div class="nav_top_2011">
<p><span style="color:red;">您还未登录！</span>|<a href="https://passport.csdn.net/account/login" target="_top">登录</a>|<a href="https://passport.csdn.net/account/register" target="_top">注册</a>|<a href="https://passport.csdn.net/help/faq" target="_blank">帮助</a></p><ul>
<li><a href="http://www.csdn.net/" target="_blank" style="color: red;">首页</a></li>
<li><a href="http://news.csdn.net/" target="_blank">业界</a></li>
<li><a href="http://mobile.csdn.net/" target="_blank">移动</a></li>
<li><a href="http://cloud.csdn.net/" target="_blank">云计算</a></li>
<li><a href="http://sd.csdn.net/" target="_blank">研发</a></li>
<li><a href="http://bbs.csdn.net/" target="_blank">论坛</a></li>
<li><a href="http://blog.csdn.net/" target="_blank">博客</a></li>
<li><a href="http://download.csdn.net/" target="_blank">下载</a></li>
<li class="more"><h2 id="topnav_btnmore" onclick="showNavMore(this)"><a href="javascript:void(0);">更多</a></h2>
<div id="topnav_hidlist">
<iframe name="nav_frm" src="7798046_files/a.htm" frameborder="no" height="178" scrolling="no" width="92"></iframe>
</div>
</li>
</ul>
</div>


<div id="container">
<div id="header">
    <div class="header">
        <div id="blog_title">
            <h1><a href="http://blog.csdn.net/sbfivwsll">銠槍--突廆孒</a></h1>
            <h2>迗哋吥仁，じ人萬粅ゐ刍狗！          聖亽吥仁，視苡絔姓莋蝼蚁！</h2>
            <div class="clear"></div>
        </div>
        <div class="clear"></div>
    </div>
</div>
<div id="navigator">
    <div class="navigator_bg"></div>
    <div class="navigator">
        <ul>
            <li id="btnContents"><a href="http://blog.csdn.net/sbfivwsll?viewmode=contents"><span><img src="7798046_files/ico_list.gif">目录视图</span></a></li>
            <li id="btnView"><a href="http://blog.csdn.net/sbfivwsll?viewmode=list"><span><img src="7798046_files/ico_summary.gif">摘要视图</span></a></li>
            <li id="btnRss"><a href="http://blog.csdn.net/sbfivwsll/rss/list"><span><img src="7798046_files/ico_rss.gif">订阅</span></a></li>
</ul>
    </div>
</div>
<script type="text/javascript">
    var username = "sbfivwsll";
    var _blogger = username;
    var blog_address = "http://blog.csdn.net/sbfivwsll";
    var static_host = "http://static.blog.csdn.net";
    var currentUserName = "";
</script>

<div id="body">
<div id="main">
<div class="main">
<div class="notice"> 

<a href="http://blog.csdn.net/blogdevteam/article/details/8899926" target="_blank">
<font color="red">有奖征集活动系列——【HTML5游戏编程之旅】 
   </font></a>



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://www.csdn.net/article/2013-05-28/2815458" target="_blank"><font color="blue">专访邱俊涛：高级JavaScript程序员的代码规范
</font></a>

&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://ocow.csdn.net/" target="_blank">
<font color="red">低价抢购开源中国论坛门票


 </font></a>

&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://blog.csdn.net/blogdevteam/article/details/8900468" target="_blank">
<font color="red">CSDN博客第一期云计算最佳博主评选
 </font></a>


&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://blog.csdn.net/blogdevteam/article/details/8853291" target="_blank">
<font color="blue">CSDN博客第二期最佳移动开发博主评选
 </font></a>




</div>
<div id="article_details" class="details">
    <div class="article_title">
    <span class="ico ico_type_Original"></span>
    <h3>
        <span class="link_title"><a href="http://blog.csdn.net/sbfivwsll/article/details/7798046">
        JTable 为单元格添加按钮效果和事件效果
        </a></span>
    </h3>
</div>

        
    <div class="article_manage">
        <span class="link_categories">
        分类：
            <a href="http://blog.csdn.net/sbfivwsll/article/category/1079839">程序日志</a> 
        </span>
    <span class="link_postdate">2012-07-29 00:24</span>
    <span class="link_view" title="阅读次数">1284人阅读</span>
    <span class="link_comments" title="评论次数"><a href="#comments">评论</a>(2)</span>
    <span class="link_collect"><a href="javascript:void(0);" onclick="javascript:collectArticle('JTable 为单元格添加按钮效果和事件效果','7798046');return false;" title="收藏">收藏</a></span>
    <span class="link_report"><a href="#report" onclick="javascript:report(7798046,2);return false;" title="举报">举报</a></span>
    
</div>
<div class="tag2box"><a href="http://blog.csdn.net/tag/details.html?tag=button" target="_blank">button</a><a href="http://blog.csdn.net/tag/details.html?tag=object" target="_blank">object</a><a href="http://blog.csdn.net/tag/details.html?tag=null" target="_blank">null</a><a href="http://blog.csdn.net/tag/details.html?tag=table" target="_blank">table</a><a href="http://blog.csdn.net/tag/details.html?tag=exception" target="_blank">exception</a><a href="http://blog.csdn.net/tag/details.html?tag=class" target="_blank">class</a></div>


    
<div id="article_content" class="article_content">

<p><span style="font-size:24px; color:#cc0000"><strong>一、添加按钮显示效果</strong></span></p>
<p>在JTable中，单元格的数据默认是Label的效果，也没有事件。</p>
<p>如果要为单元格添加一个按钮显示效果的话，那么就需要使用到一个swing的接口：javax.swing.table.TableCellRenderer，来改变单元桥格的默认默认渲染方法（DefaultTableCellRenderer），</p>
<p>实现的自定义的渲染器如下：</p>
<p>&nbsp;</p>
<div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><b>[java]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 373px; top: 586px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="7798046_files/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_1" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=18&amp;height=18" wmode="transparent" align="middle" height="18" width="18"></div></div></div><ol class="dp-j" start="1"><li class="alt"><span><span class="keyword">package</span><span>&nbsp;org.sky.table.render;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;java.awt.Component;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;javax.swing.JButton;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">import</span><span>&nbsp;javax.swing.JPanel;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;javax.swing.JTable;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">import</span><span>&nbsp;javax.swing.table.TableCellRenderer;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;MyButtonRender&nbsp;</span><span class="keyword">implements</span><span>&nbsp;TableCellRenderer&nbsp;&nbsp;</span></span></li><li class="alt"><span>{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JPanel&nbsp;panel;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JButton&nbsp;button;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;MyButtonRender()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.initButton();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.initPanel();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;添加按钮。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel.add(</span><span class="keyword">this</span><span>.button);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;initButton()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JButton();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;设置按钮的大小及位置。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button.setBounds(</span><span class="number">0</span><span>,&nbsp;</span><span class="number">0</span><span>,&nbsp;</span><span class="number">50</span><span>,&nbsp;</span><span class="number">15</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;在渲染器里边添加按钮的事件是不会触发的</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;this.button.addActionListener(new&nbsp;ActionListener()</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;{</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;public&nbsp;void&nbsp;actionPerformed(ActionEvent&nbsp;e)</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;{</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;//&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;}</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;});</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;initPanel()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JPanel();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;panel使用绝对定位，这样button就不会充满整个单元格。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel.setLayout(</span><span class="keyword">null</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Component&nbsp;getTableCellRendererComponent(JTable&nbsp;table,&nbsp;Object&nbsp;value,&nbsp;</span><span class="keyword">boolean</span><span>&nbsp;isSelected,&nbsp;</span><span class="keyword">boolean</span><span>&nbsp;hasFocus,&nbsp;</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;只为按钮赋值即可。也可以作其它操作，如绘背景等。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button.setText(value&nbsp;==&nbsp;</span><span class="keyword">null</span><span>&nbsp;?&nbsp;</span><span class="string">""</span><span>&nbsp;:&nbsp;String.valueOf(value));&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>.panel;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" class="java" name="code">package org.sky.table.render;

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class MyButtonRender implements TableCellRenderer
{
    private JPanel panel;

    private JButton button;

    public MyButtonRender()
    {
        this.initButton();

        this.initPanel();

        // 添加按钮。
        this.panel.add(this.button);
    }

    private void initButton()
    {
        this.button = new JButton();

        // 设置按钮的大小及位置。
        this.button.setBounds(0, 0, 50, 15);

        // 在渲染器里边添加按钮的事件是不会触发的
        // this.button.addActionListener(new ActionListener()
        // {
        //
        // public void actionPerformed(ActionEvent e)
        // {
        // // TODO Auto-generated method stub
        // }
        // });

    }

    private void initPanel()
    {
        this.panel = new JPanel();

        // panel使用绝对定位，这样button就不会充满整个单元格。
        this.panel.setLayout(null);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
            int column)
    {
        // 只为按钮赋值即可。也可以作其它操作，如绘背景等。
        this.button.setText(value == null ? "" : String.valueOf(value));

        return this.panel;
    }

}
</pre>
<p><br>
</p>
<p>修改表格的渲染器：this.table.getColumnModel().getColumn(2).setCellRenderer(new MyButtonRender());//只有获取到表格的列后才能添加渲染器。</p>
<p>&nbsp;</p>
<p><span style="font-size:24px; color:#cc0000"><strong>二、添加事件</strong></span></p>
<p>通过第一部已经为表格添加了默认的渲染器，但是还无法触发事件，触发事件是没有反应的，因为在点击表格时，会触发表格的编辑事件，而要想触发渲染的按钮的事件，还需要通过修改表格的默认编辑器来实现：</p>
<p>&nbsp;&nbsp;</p>
<div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><b>[java]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 373px; top: 1927px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_2" src="7798046_files/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_2" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=18&amp;height=18" wmode="transparent" align="middle" height="18" width="18"></div></div></div><ol class="dp-j" start="1"><li class="alt"><span><span class="keyword">package</span><span>&nbsp;org.sky.table.editor;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;java.awt.Component;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">import</span><span>&nbsp;java.awt.event.ActionEvent;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;java.awt.event.ActionListener;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;javax.swing.DefaultCellEditor;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">import</span><span>&nbsp;javax.swing.JButton;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;javax.swing.JPanel;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">import</span><span>&nbsp;javax.swing.JTable;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;javax.swing.JTextField;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="comment">/**</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;*&nbsp;自定义一个往列里边添加按钮的单元格编辑器。最好继承DefaultCellEditor，不然要实现的方法就太多了。</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;*&nbsp;</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;MyButtonEditor&nbsp;</span><span class="keyword">extends</span><span>&nbsp;DefaultCellEditor&nbsp;&nbsp;</span></span></li><li class=""><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;serialVersionUID</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">final</span><span>&nbsp;</span><span class="keyword">long</span><span>&nbsp;serialVersionUID&nbsp;=&nbsp;-6546334664166791132L;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JPanel&nbsp;panel;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JButton&nbsp;button;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;MyButtonEditor()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;DefautlCellEditor有此构造器，需要传入一个，但这个不会使用到，直接new一个即可。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">super</span><span>(</span><span class="keyword">new</span><span>&nbsp;JTextField());&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;设置点击几次激活编辑。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.setClickCountToStart(</span><span class="number">1</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.initButton();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.initPanel();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;添加按钮。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel.add(</span><span class="keyword">this</span><span>.button);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;initButton()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JButton();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;设置按钮的大小及位置。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button.setBounds(</span><span class="number">0</span><span>,&nbsp;</span><span class="number">0</span><span>,&nbsp;</span><span class="number">50</span><span>,&nbsp;</span><span class="number">15</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;为按钮添加事件。这里只能添加ActionListner事件，Mouse事件无效。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button.addActionListener(</span><span class="keyword">new</span><span>&nbsp;ActionListener()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;actionPerformed(ActionEvent&nbsp;e)&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;触发取消编辑的事件，不会调用tableModel的setValue方法。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyButtonEditor.<span class="keyword">this</span><span>.fireEditingCanceled();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;这里可以做其它操作。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;可以将table传入，通过getSelectedRow,getSelectColumn方法获取到当前选择的行和列及其它操作等。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;initPanel()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JPanel();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;panel使用绝对定位，这样button就不会充满整个单元格。</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.panel.setLayout(</span><span class="keyword">null</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;这里重写父类的编辑方法，返回一个JPanel对象即可（也可以直接返回一个Button对象，但是那样会填充满整个单元格）</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Component&nbsp;getTableCellEditorComponent(JTable&nbsp;table,&nbsp;Object&nbsp;value,&nbsp;</span><span class="keyword">boolean</span><span>&nbsp;isSelected,&nbsp;</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;</span><span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;只为按钮赋值即可。也可以作其它操作。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.button.setText(value&nbsp;==&nbsp;</span><span class="keyword">null</span><span>&nbsp;?&nbsp;</span><span class="string">""</span><span>&nbsp;:&nbsp;String.valueOf(value));&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>.panel;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;重写编辑单元格时获取的值。如果不重写，这里可能会为按钮设置错误的值。</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Object&nbsp;getCellEditorValue()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>.button.getText();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" class="java" name="code">package org.sky.table.editor;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;

/**
 * 自定义一个往列里边添加按钮的单元格编辑器。最好继承DefaultCellEditor，不然要实现的方法就太多了。
 * 
 */
public class MyButtonEditor extends DefaultCellEditor
{

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -6546334664166791132L;

    private JPanel panel;

    private JButton button;

    public MyButtonEditor()
    {
        // DefautlCellEditor有此构造器，需要传入一个，但这个不会使用到，直接new一个即可。
        super(new JTextField());

        // 设置点击几次激活编辑。
        this.setClickCountToStart(1);

        this.initButton();

        this.initPanel();

        // 添加按钮。
        this.panel.add(this.button);
    }

    private void initButton()
    {
        this.button = new JButton();

        // 设置按钮的大小及位置。
        this.button.setBounds(0, 0, 50, 15);

        // 为按钮添加事件。这里只能添加ActionListner事件，Mouse事件无效。
        this.button.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                // 触发取消编辑的事件，不会调用tableModel的setValue方法。
                MyButtonEditor.this.fireEditingCanceled();

                // 这里可以做其它操作。
                // 可以将table传入，通过getSelectedRow,getSelectColumn方法获取到当前选择的行和列及其它操作等。
            }
        });

    }

    private void initPanel()
    {
        this.panel = new JPanel();

        // panel使用绝对定位，这样button就不会充满整个单元格。
        this.panel.setLayout(null);
    }


    /**
     * 这里重写父类的编辑方法，返回一个JPanel对象即可（也可以直接返回一个Button对象，但是那样会填充满整个单元格）
     */
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
    {
        // 只为按钮赋值即可。也可以作其它操作。
        this.button.setText(value == null ? "" : String.valueOf(value));

        return this.panel;
    }

    /**
     * 重写编辑单元格时获取的值。如果不重写，这里可能会为按钮设置错误的值。
     */
    @Override
    public Object getCellEditorValue()
    {
        return this.button.getText();
    }

}
</pre>
<p><br>
修改表格的默认编辑器：</p>
<p>this.table.getColumnModel().getColumn(2).setCellEditor(new MyButtonEditor());</p>
<p>&nbsp;</p>
<p>这样后就能基本达到效果了。但是还要注意，对列2来说，还需要启用可编辑功能，才行，不然仍然触发不了事件的。</p>
<p>代码片段：</p>
<div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><b>[java]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 373px; top: 3898px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_3" src="7798046_files/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_3" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=18&amp;height=18" wmode="transparent" align="middle" height="18" width="18"></div></div></div><ol class="dp-j" start="1"><li class="alt"><span><span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">boolean</span><span>&nbsp;isCellEditable(</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;</span><span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;带有按钮列的功能这里必须要返回true不然按钮点击时不会触发编辑效果，也就不会触发事件。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(column&nbsp;==&nbsp;</span><span class="number">2</span><span>)&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">true</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">else</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">false</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" class="java" name="code">            @Override
            public boolean isCellEditable(int row, int column)
            {
                // 带有按钮列的功能这里必须要返回true不然按钮点击时不会触发编辑效果，也就不会触发事件。
                if (column == 2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }</pre>
<p><br>
&nbsp;</p>
<p><strong><span style="font-size:24px; color:#cc0000">三、测试代码：</span></strong></p>
<p>测试代码的界面是由windowbuilder插件生成的，懒得自己去写干净的代码了，所以下边的代码有点冗余，大家看表格下边的那段代码即可：</p>
<div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><b>[java]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 373px; top: 4305px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_4" src="7798046_files/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_4" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=18&amp;height=18" wmode="transparent" align="middle" height="18" width="18"></div></div></div><ol class="dp-j" start="1"><li class="alt"><span><span class="keyword">package</span><span>&nbsp;org.sky.table.frame;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">import</span><span>&nbsp;java.awt.EventQueue;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;TestTable&nbsp;&nbsp;</span></span></li><li class=""><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JFrame&nbsp;frame;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;JTable&nbsp;table;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Launch&nbsp;the&nbsp;application.</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;main(String[]&nbsp;args)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EventQueue.invokeLater(<span class="keyword">new</span><span>&nbsp;Runnable()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;run()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">try</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TestTable&nbsp;window&nbsp;=&nbsp;<span class="keyword">new</span><span>&nbsp;TestTable();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.frame.setVisible(<span class="keyword">true</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">catch</span><span>&nbsp;(Exception&nbsp;e)&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Create&nbsp;the&nbsp;application.</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;TestTable()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.initialize();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">/**</span>&nbsp;</span></li><li class=""><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Initialize&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;frame.</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;initialize()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.frame&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JFrame();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.frame.setBounds(</span><span class="number">100</span><span>,&nbsp;</span><span class="number">100</span><span>,&nbsp;</span><span class="number">450</span><span>,&nbsp;</span><span class="number">300</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.frame.getContentPane().setLayout(</span><span class="keyword">null</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JPanel&nbsp;panel&nbsp;=&nbsp;<span class="keyword">new</span><span>&nbsp;JPanel();&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;panel.setBounds(<span class="number">10</span><span>,&nbsp;</span><span class="number">10</span><span>,&nbsp;</span><span class="number">414</span><span>,&nbsp;</span><span class="number">242</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.frame.getContentPane().add(panel);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;panel.setLayout(<span class="keyword">null</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JScrollPane&nbsp;scrollPane&nbsp;=&nbsp;<span class="keyword">new</span><span>&nbsp;JScrollPane();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPane.setBounds(<span class="number">10</span><span>,&nbsp;</span><span class="number">10</span><span>,&nbsp;</span><span class="number">394</span><span>,&nbsp;</span><span class="number">222</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;panel.add(scrollPane);&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.table&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;JTable();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPane.setViewportView(<span class="keyword">this</span><span>.table);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.table.setModel(</span><span class="keyword">new</span><span>&nbsp;DefaultTableModel()&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Object&nbsp;getValueAt(</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;</span><span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;(row&nbsp;+&nbsp;</span><span class="number">1</span><span>)&nbsp;*&nbsp;(column&nbsp;+&nbsp;</span><span class="number">1</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">int</span><span>&nbsp;getRowCount()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="number">3</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">int</span><span>&nbsp;getColumnCount()&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="number">3</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;setValueAt(Object&nbsp;aValue,&nbsp;</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;</span><span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(aValue&nbsp;+&nbsp;<span class="string">"&nbsp;&nbsp;setValueAt"</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation">@Override</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">boolean</span><span>&nbsp;isCellEditable(</span><span class="keyword">int</span><span>&nbsp;row,&nbsp;</span><span class="keyword">int</span><span>&nbsp;column)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;带有按钮列的功能这里必须要返回true不然按钮点击时不会触发编辑效果，也就不会触发事件。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(column&nbsp;==&nbsp;</span><span class="number">2</span><span>)&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">true</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">else</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">false</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.table.getColumnModel().getColumn(</span><span class="number">2</span><span>).setCellEditor(</span><span class="keyword">new</span><span>&nbsp;MyButtonEditor());&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.table.getColumnModel().getColumn(</span><span class="number">2</span><span>).setCellRenderer(</span><span class="keyword">new</span><span>&nbsp;MyButtonRender());&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">this</span><span>.table.setRowSelectionAllowed(</span><span class="keyword">false</span><span>);</span><span class="comment">//&nbsp;禁止表格的选择功能。不然在点击按钮时表格的整行都会被选中。也可以通过其它方式来实现。</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" class="java" name="code">package org.sky.table.frame;

import java.awt.EventQueue;

public class TestTable
{

    private JFrame frame;
    private JTable table;

    /**
     * Launch the application.
     */
    public static void main(String[] args)
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    TestTable window = new TestTable();
                    window.frame.setVisible(true);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public TestTable()
    {
        this.initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize()
    {
        this.frame = new JFrame();
        this.frame.setBounds(100, 100, 450, 300);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.frame.getContentPane().setLayout(null);

        JPanel panel = new JPanel();
        panel.setBounds(10, 10, 414, 242);
        this.frame.getContentPane().add(panel);
        panel.setLayout(null);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(10, 10, 394, 222);
        panel.add(scrollPane);

        this.table = new JTable();
        scrollPane.setViewportView(this.table);

        this.table.setModel(new DefaultTableModel()
        {
            @Override
            public Object getValueAt(int row, int column)
            {
                return (row + 1) * (column + 1);
            }

            @Override
            public int getRowCount()
            {
                return 3;
            }

            @Override
            public int getColumnCount()
            {
                return 3;
            }

            @Override
            public void setValueAt(Object aValue, int row, int column)
            {
                System.out.println(aValue + "  setValueAt");
            }

            @Override
            public boolean isCellEditable(int row, int column)
            {
                // 带有按钮列的功能这里必须要返回true不然按钮点击时不会触发编辑效果，也就不会触发事件。
                if (column == 2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        });

        this.table.getColumnModel().getColumn(2).setCellEditor(new MyButtonEditor());

        this.table.getColumnModel().getColumn(2).setCellRenderer(new MyButtonRender());

        this.table.setRowSelectionAllowed(false);// 禁止表格的选择功能。不然在点击按钮时表格的整行都会被选中。也可以通过其它方式来实现。
    }
}
</pre>
<p><br>
&nbsp;</p>

</div>

<div class="share_buttons" id="sharePanel"><span>分享到：</span> <a name="sina" class="share_sina" title="分享到新浪微博"></a><a name="qq" class="share_qq" title="分享到腾讯微博"></a></div>
<!--192.168.100.33-->
<div class="article_next_prev">
    <li class="prev_article"><span>上一篇：</span><a href="http://blog.csdn.net/sbfivwsll/article/details/7694366">Spket 破解方法</a></li>
    <li class="next_article"><span>下一篇：</span><a href="http://blog.csdn.net/sbfivwsll/article/details/7803611">“记住密码“功能的正确设计</a></li>
</div>


    
</div>
<div id="ad_cen">
<script type="text/javascript">BAIDU_CLB_SLOT_ID = "117306";</script>
<script type="text/javascript" src="7798046_files/o.js"></script><script charset="utf-8" src="7798046_files/ecom"></script><script type="text/javascript"><!--
google_ad_client = "ca-pub-1076724771190722";
/* blog正文下方728x90 */
google_ad_slot = "4497271841";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript" src="7798046_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:728px"><ins id="aswift_0_anchor" style="display:block;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:728px"><iframe marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;" frameborder="0" height="90" scrolling="no" width="728"></iframe></ins></ins>
</div>
<script type="text/javascript">
    //new Ad(4, 'ad_cen');
</script>
<div id="comment_title" class="panel_head">查看评论<a name="comments"></a></div>
<div id="comment_list"><dl class="comment_item comment_topic" id="comment_item_2634744"><dt class="comment_head" floor="2">2楼 <span class="user"><a class="username" href="http://blog.csdn.net/ErinToJerry" target="_blank">ErinToJerry</a> <span class="ptime">2013-05-20 09:45发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="2634744" username="ErinToJerry"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="http://blog.csdn.net/ErinToJerry" target="_blank"><img src="7798046_files/3_erintojerry.gif" height="40" width="40"></a></dd><dd class="comment_body">参考您的文章，我也写了一篇：<br>http://huachichi.info/2013/05/17/add-button-to-jtable-cell/</dd></dl><dl class="comment_item comment_topic" id="comment_item_2631670"><dt class="comment_head" floor="1">1楼 <span class="user"><a class="username" href="http://blog.csdn.net/ErinToJerry" target="_blank">ErinToJerry</a> <span class="ptime">2013-05-17 10:05发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="2631670" username="ErinToJerry"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="http://blog.csdn.net/ErinToJerry" target="_blank"><img src="7798046_files/3_erintojerry.gif" height="40" width="40"></a></dd><dd class="comment_body">您把TableModel的setValueAt方法重写了有弊端，您写的是简单的System.out.println语句。弊端就是单元格的数据不能够更新，就是不能够更改为其他值。……</dd></dl><div class="clear"></div></div>
<div style="display: none;" id="comment_bar"></div>
<div id="comment_form"><div class="guest_link">您还没有登录,请<a href="javascript:void(0);" onclick="javascript:csdn.showLogin(function (dat) {js_logined(dat.data.userName);});">[登录]</a>或<a href="http://passport.csdn.net/account/register?from=http%3A%2F%2Fblog.csdn.net%2Fsbfivwsll%2Farticle%2Fdetails%2F7798046">[注册]</a></div></div>
<div class="announce">* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场<a name="reply"></a><a name="quote"></a></div>
<script type="text/javascript">
    var fileName = '7798046';
    var commentscount = 2;
    var islock = false
</script>
<script type="text/javascript" src="7798046_files/comment.js"></script>
<div id="ad_bot"><iframe src="7798046_files/ad.htm" style="border-width: 0px; overflow: hidden; width: 1648px; height: 170px;" id="ad_frm_0" frameborder="0" scrolling="no"></iframe></div>
<script type="text/javascript">
    new Ad(5, 'ad_bot');
</script>
<div id="report_dialog"></div>

<div id="d-top" style="display: block;">
<a id="d-top-a" href="#" title="回到顶部">
<img src="7798046_files/top.png" alt="TOP"></a>
</div>
<script type="text/javascript">
    $(function(){
        var d_top=$('#d-top');
        document.onscroll=function(){
            var scrTop=(document.body.scrollTop||document.documentElement.scrollTop);
            if(scrTop>500){
                d_top.show();
            }else{
                d_top.hide();
            }
        }
        $('#d-top-a').click(function(){
            scrollTo(0,0);
            this.blur();
            return false;
        });
    });
</script>

<div class="clear"></div>
</div>
</div>

<div id="side">
<div class="side">
<div id="panel_Profile" class="panel">
<ul class="panel_head"><span>个人资料</span></ul>
<ul class="panel_body profile">
<div id="blog_userface">
    <a href="http://my.csdn.net/sbfivwsll" target="_blank">
    <img src="7798046_files/1_sbfivwsll.jpg" title="访问我的空间" style="max-width:90%">
    </a>
    <br>
    <span><a href="http://my.csdn.net/sbfivwsll" class="user_name" target="_blank">铑枪--突廆孒</a></span>
</div>
<div class="interact">
<a href="javascript:void(0);" class="attent" id="span_add_follow" title="[加关注]"></a>
<a href="javascript:void(0);" class="letter" onclick="loginto(1)" title="[发私信]"></a>
</div>
<div id="blog_medal">
<div id="bms_box"><a href="http://medal.blog.csdn.net/allmedal.aspx" target="_blank"><img src="7798046_files/holdon_s2.gif" onmouseover="m_over_m(this,0)" onmouseout="m_out_m()" alt=""></a></div></div>
<ul id="blog_rank">
    <li>访问：<span>69574次</span></li>
    <li>积分：<span>1171分</span></li>
    <li>排名：<span>第8582名</span></li>
</ul>
<ul id="blog_statistics">
    <li>原创：<span>39篇</span></li>
    <li>转载：<span>35篇</span></li>
    <li>译文：<span>0篇</span></li>
    <li>评论：<span>19条</span></li>
</ul>
</ul>
</div>



<div class="panel" id="panel_Search">
    <ul class="panel_head"><span>文章搜索</span></ul>
    <ul class="panel_body">
        <form id="frmSearch" action="http://so.csdn.net/search" class="form_search" target="_blank">
        <span><input id="inputSearch" class="blogsearch" title="请输入关键字" type="text"></span>
        <input id="btnSubmit" value="搜索" title="search in blog" type="submit">
        <input name="q" id="inputQ" type="hidden">
        <input name="t" value="blog" type="hidden">
        <a id="btnSearchBlog" target="_blank"></a>
        </form>
    </ul>
</div><div id="panel_Category" class="panel">
<ul class="panel_head"><span>文章分类</span></ul>
<ul class="panel_body">
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/category/719013">Windows Gadget</a><span>(3)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/category/620418">电脑维护</a><span>(3)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/category/693476">资源下载</a><span>(1)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/category/905635">电脑知识</a><span>(1)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/category/1079839">程序日志</a><span>(22)</span>
</li>
</ul>
</div><div id="panel_Archive" class="panel">
<ul class="panel_head"><span>文章存档</span></ul>
<ul class="panel_body">
<div id="archive_list"><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/11">2012年11月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/10">2012年10月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/09">2012年09月</a><span>(2)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/08">2012年08月</a><span>(4)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/07">2012年07月</a><span>(2)</span></li><span class="hidelist" style="display:none;"><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/06">2012年06月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/05">2012年05月</a><span>(3)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/04">2012年04月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/03">2012年03月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2012/02">2012年02月</a><span>(11)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2011/10">2011年10月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/11">2010年11月</a><span>(2)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/09">2010年09月</a><span>(4)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/08">2010年08月</a><span>(4)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/07">2010年07月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/05">2010年05月</a><span>(3)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/04">2010年04月</a><span>(6)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/03">2010年03月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/02">2010年02月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2010/01">2010年01月</a><span>(4)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2009/12">2009年12月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2009/11">2009年11月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2009/07">2009年07月</a><span>(15)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2009/03">2009年03月</a><span>(1)</span></li><li><a href="http://blog.csdn.net/sbfivwsll/article/month/2009/01">2009年01月</a><span>(2)</span></li></span><div id="archive_list_button" class="list_closed">展开</div></div>
</ul>
</div>
<div id="hotarticls" class="panel">
<ul class="panel_head"><span>阅读排行</span></ul>
<ul class="panel_body itemlist">
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/3992302" title="div嵌套页面 div加载页面 (其中获取目标页面的内容是用dwr框架连接java程序做的)">div嵌套页面 div加载页面 (其中获取目标页面的内容是用dwr框架连接java程序做的)</a><span>(6248)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5443135" title="WINDOWS7没有&quot;发送到桌面快捷方式“">WINDOWS7没有"发送到桌面快捷方式“</a><span>(2549)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/4830222" title="华为无线猫EchoLife HG522路由配置">华为无线猫EchoLife HG522路由配置</a><span>(2396)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/4942990" title=" MyEclipse7.5+下如何安装插件"> MyEclipse7.5+下如何安装插件</a><span>(2366)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5482604" title="IE与firefox 兼容问题 (二、项目经验总结)">IE与firefox 兼容问题 (二、项目经验总结)</a><span>(2168)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7267475" title="更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者">更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者</a><span>(1687)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7798046" title="JTable 为单元格添加按钮效果和事件效果">JTable 为单元格添加按钮效果和事件效果</a><span>(1283)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7551888" title="myeclipse中关联jar包源代码 --支持自带jar包源代码的关联">myeclipse中关联jar包源代码 --支持自带jar包源代码的关联</a><span>(1136)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5547854" title="JSON与JAVA数据的相互转换(基本应用) ">JSON与JAVA数据的相互转换(基本应用) </a><span>(1108)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/6882138" title="深圳市租房提取住房公积金攻略">深圳市租房提取住房公积金攻略</a><span>(1088)</span>
</li>
</ul>
</div>
<div id="hotarticls2" class="panel">
<ul class="panel_head"><span>评论排行</span></ul>
<ul class="panel_body itemlist">
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5789287" title="Windows Gagdget 制作 (一)">Windows Gagdget 制作 (一)</a><span>(4)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5735817" title="MyEclipse中变量变色的问题">MyEclipse中变量变色的问题</a><span>(3)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5482604" title="IE与firefox 兼容问题 (二、项目经验总结)">IE与firefox 兼容问题 (二、项目经验总结)</a><span>(2)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/6030966" title="在Java中正确实现可序列化接口(Serializable)">在Java中正确实现可序列化接口(Serializable)</a><span>(2)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7267475" title="更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者">更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者</a><span>(2)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7798046" title="JTable 为单元格添加按钮效果和事件效果">JTable 为单元格添加按钮效果和事件效果</a><span>(2)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5856569" title="ie8下使用JSON让人吐血的问题(三场由html头文件引发的“血案”) ">ie8下使用JSON让人吐血的问题(三场由html头文件引发的“血案”) </a><span>(2)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7267462" title="在MyEclipse 中添加自己定义的文件模版(----为myeclipse新建一个tapestry 5的tml模板)">在MyEclipse 中添加自己定义的文件模版(----为myeclipse新建一个tapestry 5的tml模板)</a><span>(1)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/5443135" title="WINDOWS7没有&quot;发送到桌面快捷方式“">WINDOWS7没有"发送到桌面快捷方式“</a><span>(1)</span>
</li>
<li>
<a href="http://blog.csdn.net/sbfivwsll/article/details/7267482" title="Java toLowerCase()/toUpperCase()方法的使用注意">Java toLowerCase()/toUpperCase()方法的使用注意</a><span>(0)</span>
</li>
</ul>
</div>
<div id="homepageArticles" class="panel">
<ul class="panel_head"><span>推荐文章</span></ul>
<ul class="panel_body" id="ad_commend"><iframe src="7798046_files/ad_002.htm" style="border-width: 0px; overflow: hidden; width: 194px; height: 236px;" id="ad_frm_1" frameborder="0" scrolling="no"></iframe></ul>
</div>
<script type="text/javascript">
 new Ad(12, 'ad_commend');
</script><div id="newcomments" class="panel">
<ul class="panel_head"><span>最新评论</span></ul>
<ul class="panel_body itemlist">
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/7267475#comments">更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/stevenshanbao" class="user_name">stevenshanbao</a>:
学习了
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/7798046#comments">JTable 为单元格添加按钮效果和事件效果</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/ErinToJerry" class="user_name">ErinToJerry</a>:
参考您的文章，我也写了一篇：http://huachichi.info/2013/05/17/add...
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/7798046#comments">JTable 为单元格添加按钮效果和事件效果</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/ErinToJerry" class="user_name">ErinToJerry</a>:
您把TableModel的setValueAt方法重写了有弊端，您写的是简单的System.out....
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/7267475#comments">更改eclipse(myeclipse) author的默认名字 --- 修改MyEclipse eclipse 注释的作者</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/wym2011aaj" class="user_name">wym2011aaj</a>:
System.out.println("3q");
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5482604#comments">IE与firefox 兼容问题 (二、项目经验总结)</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/z379715422" class="user_name">EricJean</a>:
很强大呀！！
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5735817#comments">MyEclipse中变量变色的问题</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/oFuFuChenChen" class="user_name">oFuFuChenChen</a>:
灰常感谢，没这叼东西太不方便了
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5735817#comments">MyEclipse中变量变色的问题</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/zhongxiaweimian" class="user_name">zhongxiaweimian</a>:
感谢LZ呢恩！
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5735817#comments">MyEclipse中变量变色的问题</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/hui840319" class="user_name">hui840319</a>:
恩 找到了 非常感谢！！
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5443135#comments">WINDOWS7没有"发送到桌面快捷方式“</a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/jiana227" class="user_name">jiana227</a>:
真的么
    </p>
    </li>
    <li>
    <a href="http://blog.csdn.net/sbfivwsll/article/details/5856569#comments">ie8下使用JSON让人吐血的问题(三场由html头文件引发的“血案”) </a>
    <p style="margin:0px;"><a href="http://blog.csdn.net/sbfivwsll" class="user_name">铑枪--突廆孒</a>:
你在html里边添加上doctype的头文件信息再试一下。
    </p>
    </li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>

<div class="clear"></div>
</div>

<script type="text/javascript" src="7798046_files/newblog.js"></script>
<script type="text/javascript" src="7798046_files/showblogmedal.js"></script>

<script type="text/javascript">
document.write('<script type="text/javascript" src="http://csdnimg.cn/pubfooter/js/publib_footer.js?' + Math.floor(new Date()/120000).toString(36) + '="></'+'script>');
</script><script type="text/javascript" src="7798046_files/publib_footer.js"></script><link rel="stylesheet" type="text/css" href="7798046_files/pub_footer_2012.css"><div id="pub_footerall" class="pub_footerall"><dl><dt></dt> <dd><a href="http://www.csdn.net/company/about.html" target="_blank">公司简介</a>|<a href="http://www.csdn.net/company/recruit.html" target="_blank">招贤纳士</a>|<a href="http://www.csdn.net/company/marketing.html" target="_blank">广告服务</a>|<a href="http://www.csdn.net/company/account.html" target="_blank">银行汇款帐号</a>|<a href="http://www.csdn.net/company/contact.html" target="_blank">联系方式</a>|<a href="http://www.csdn.net/company/statement.html" target="_blank">版权声明</a>|<a href="http://www.csdn.net/company/layer.html" target="_blank">法律顾问</a>|<a href="mailto:webmaster@csdn.net">问题报告</a></dd><dd><a href="http://wpa.qq.com/msgrd?v=3&amp;uin=2355263776&amp;site=qq&amp;menu=yes" target="_blank" class="qq">QQ客服</a> <a href="http://e.weibo.com/csdnsupport/profile" target="_blank" class="weibo">微博客服</a> <a href="http://bbs.csdn.net/forums/Service" target="_blank" class="online">论坛反馈</a> <a href="mailto:webmaster@csdn.net" class="email">联系邮箱：webmaster@csdn.net</a> <span class="phone">服务热线：400-600-2320</span></dd><dd>京&nbsp;ICP&nbsp;证&nbsp;070598&nbsp;号</dd><dd>北京创新乐知信息技术有限公司 版权所有</dd><dd>世纪乐知(北京)网络技术有限公司 提供技术支持</dd><dd>江苏乐知网络技术有限公司 提供商务支持</dd><dd>Copyright © 1999-2012, CSDN.NET, All Rights Reserved&nbsp;<a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010" target="_blank"><img src="7798046_files/gongshang_logos.gif" alt="GongshangLogo" title=""></a></dd></dl></div><script id="noticeScript" type="text/javascript" btnid="header_notice_num" wrapid="note1" count="5" subcount="5" src="7798046_files/note.js"></script><script type="text/javascript" charset="utf-8" src="7798046_files/tracking.js"></script>

<script type="text/javascript" src="7798046_files/login.js"></script>
<script type="text/javascript">document.write("<img src=http://counter.csdn.net/pv.aspx?id=24 border=0 width=0 height=0>");</script><img src="7798046_files/pv.txt" border="0" height="0" width="0">
<script type="text/javascript" src="7798046_files/counter.js"></script><script type="text/javascript" charset="UTF-8" src="7798046_files/msg.js"></script>


<script type="text/javascript" src="7798046_files/ad-blog.js"></script><script type="text/javascript" src="7798046_files/ad-ms521.js"></script>
<script type="text/javascript" src="7798046_files/ad-ms518.js"></script>


</div>

<iframe src="7798046_files/log.swf" style="width: 1px; height: 1px; position: absolute; visibility: hidden;"></iframe><iframe src="7798046_files/log_002.swf" style="width: 1px; height: 1px; position: absolute; visibility: hidden;"></iframe></body></html>